﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using IFRS.DataAccess.DAL;
using IFRS.Models;

namespace IFRS.DataAccess.DAL
{
    public class SPR_RECLASSIFICATION
    {
        public DataTable SearchAll(Reclassification reclassification, Paging paging, ref int iRecordCount)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting));

                lstParams.Add(new SqlParameter("@TransactionDate", reclassification.TransactionDate));
                lstParams.Add(new SqlParameter("@SourceDataID", reclassification.SourceDataID));
                lstParams.Add(new SqlParameter("@AccountNo", reclassification.AccountNo));
                lstParams.Add(new SqlParameter("@NewClassifyID", reclassification.NewClassifyID));
                dt = Utility.StoredProcDataTable("SPR_RECLASSIFICATION_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int ReclassificationID)
        {
            DataTable dt = new DataTable();
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@ReclassificationID", ReclassificationID));
                dt = Utility.StoredProcDataTable("SPR_RECLASSIFICATION_SEARCHBYID", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(Reclassification reclassification)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@ReclassificationID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@SourceOfData", reclassification.SourceOfData));
                lstParams.Add(new SqlParameter("@TransactionDate", reclassification.TransactionDate));
                lstParams.Add(new SqlParameter("@SourceDataID", reclassification.SourceDataID));
                lstParams.Add(new SqlParameter("@AccountNo", reclassification.AccountNo));
                lstParams.Add(new SqlParameter("@NewClassifyID", reclassification.NewClassifyID));
                lstParams.Add(new SqlParameter("@FairValue", reclassification.FairValue));
                lstParams.Add(new SqlParameter("@IsConfirmed", reclassification.IsConfirmed));
                lstParams.Add(new SqlParameter("@CreatedDate", reclassification.CreatedDate));
                lstParams.Add(new SqlParameter("@CreatedBy", reclassification.CreatedBy));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", reclassification.CreatedCostCenter));
                lstParams.Add(new SqlParameter("@CreatedBranch", reclassification.CreatedBranch));
                lstParams.Add(new SqlParameter("@UpdatedDate", reclassification.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", reclassification.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", reclassification.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", reclassification.UpdatedBranch));

                Utility.ExecuteStoredProc("SPR_RECLASSIFICATION_INSERT", lstParams.ToArray());
                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(Reclassification reclassification)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@ReclassificationID", reclassification.ReclassificationID));
                lstParams.Add(new SqlParameter("@TransactionDate", reclassification.TransactionDate));
                lstParams.Add(new SqlParameter("@SourceDataID", reclassification.SourceDataID));
                lstParams.Add(new SqlParameter("@AccountNo", reclassification.AccountNo));
                lstParams.Add(new SqlParameter("@NewClassifyID", reclassification.NewClassifyID));
                lstParams.Add(new SqlParameter("@FairValue", reclassification.FairValue));
                lstParams.Add(new SqlParameter("@UpdatedDate", reclassification.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", reclassification.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", reclassification.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", reclassification.UpdatedBranch));

                iNum = (int)Utility.ExecuteStoredProc("SPR_RECLASSIFICATION_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(Reclassification reclassification)
        {
            int iNum = 0;
            IFRS_Utility Utility = new IFRS_Utility();
            List<SqlParameter> lstParams = new List<SqlParameter>();

            try
            {
                lstParams.Add(new SqlParameter("@ReclassificationID", reclassification.ReclassificationID));
                lstParams.Add(new SqlParameter("@UpdatedDate", reclassification.UpdatedDate));
                lstParams.Add(new SqlParameter("@UpdatedBy", reclassification.UpdatedBy));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", reclassification.UpdatedCostCenter));
                lstParams.Add(new SqlParameter("@UpdatedBranch", reclassification.UpdatedBranch));
                iNum = (int)Utility.ExecuteStoredProc("SPR_RECLASSIFICATION_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

    }
}
